home *** CD-ROM | disk | FTP | other *** search
- /*
- * SFcolours - Star Fighter 3000 colours editor
- * Iconbar icon
- * Copyright (C) 2001 Chris Bazley
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public Licence as published by
- * the Free Software Foundation; either version 2 of the Licence, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public Licence for more details.
- *
- * You should have received a copy of the GNU General Public Licence
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- /* ANSI library files */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- /* RISC OS library files */
- #include "wimp.h"
- #include "toolbox.h"
- #include "event.h"
- #include "wimplib.h"
- #include "iconbar.h"
-
- /* My library files */
- #include "err.h"
- #include "msgtrans.h"
- #include "Macros.h"
- #include "Loader.h"
- #include "SFformats.h" /* get Fednet filetype */
- #include "ViewsMenu.h"
-
- /* Local headers */
- #include "EditColmap.h"
- #include "Utils.h"
- #include "SFCCreateFile.h"
- #include "SFCIconbar.h"
-
- static ObjectId Iconbar_id;
-
- /* ----------------------------------------------------------------------- */
- /* Function prototypes */
-
- static LoaderFinishedHandler _Iconbar_openfile;
- static ToolboxEventHandler _Iconbar_click;
-
- /* ----------------------------------------------------------------------- */
- /* Public functions */
-
- void Iconbar_initialise(ObjectId id)
- {
- Iconbar_id = id;
-
- /* Listen for clicks */
- EF(event_register_toolbox_handler(id, Iconbar_Clicked, _Iconbar_click, NULL));
-
- /* Register listeners for files dropped on iconbar icon */
- EF(loader_register_listener(0, FILETYPE_FEDNET, id, NULL, load_compressed, _Iconbar_openfile, NULL));
- }
-
- /* ----------------------------------------------------------------------- */
- /* Private functions */
-
- static int _Iconbar_click(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
- {
- if(FLAG_SET(((IconbarClickedEvent *)event)->hdr.flags, Iconbar_Clicked_Select)) {
- /* create new file */
- RE(toolbox_show_object(Toolbox_ShowObject_AsMenu, CreateFile_sharedid, Toolbox_ShowObject_Centre, NULL, id_block->self_id, id_block->self_component))
- return 1; /* claim event */
- }
-
- if(FLAG_SET(((IconbarClickedEvent *)event)->hdr.flags, Iconbar_Clicked_Adjust)) {
- /* bring all open windows to front */
- RE(ViewsMenu_showall())
- return 1; /* claim event */
- }
-
- return 0; /* event not handled */
- }
-
- /* ----------------------------------------------------------------------- */
-
- static void _Iconbar_openfile(char *title, bool data_saved, flex_ptr buffer,int filetype, void *handle)
- {
- /* Open a new editing window */
- ObjectId editing_win;
-
- if(flex_size(buffer) != sizeof(SF_ColourMap) && flex_size(buffer) != sizeof(SF_HillCols)) {
- flex_free(buffer);
- M_RET("NoSuchFileType") /* Code or someting */
- }
-
- /* Check for existing windows */
- if(!data_saved || (editing_win = ViewsMenu_findview(title)) == NULL_ObjectId) {
-
- /* Create editing window */
- editing_win = EditColmap_create(buffer, (flex_size(buffer) == sizeof(SF_HillCols)), title, data_saved);
- if(editing_win == NULL) {
- flex_free(buffer);
- return;
- }
- }
- else
- flex_free(buffer); /* Already have an open editing window */
-
- /* Open editing window */
- RE(show_win_at_ptr(0, editing_win, Iconbar_id, NULL_ComponentId))
- }
-